package StudyCode.summary.zipfile;

import sun.misc.BASE64Decoder;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CompressesInputByteArrayUsingGZIP {
	public static byte[] gzip(byte[] binaryInput) throws IOException {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		GZIPOutputStream gzipOut = new GZIPOutputStream(baos);

		gzipOut.write(binaryInput);
		gzipOut.finish();
		gzipOut.close();

		return baos.toByteArray();
	}


	public static byte[] gzip(String base64Input) throws IOException {
		BASE64Decoder base64Decoder = new BASE64Decoder();
		byte[] binaryInput = base64Decoder.decodeBuffer(base64Input);

		return gzip(binaryInput);
	}
}
